﻿namespace SimpleWebServices
{
    using System;

    public static class DateTimeFactory
    {
        [ThreadStatic]
        private static DateTime? _mock;

        public static DateTime Today
        {
            get
            {
                DateTime value = DateTime.Today;

                if (null != _mock)
                {
                    value = _mock.Value.Date;
                }

                return value;
            }
        }

        public static DateTime UtcNow
        {
            get
            {
                DateTime value = DateTime.UtcNow;

                if (null != _mock)
                {
                    value = _mock.Value;
                }

                return value;
            }
        }

        public static DateTime? Mock
        {
            get
            {
                return _mock;
            }

            set
            {
                _mock = value;
            }
        }

        public static void Reset()
        {
            DateTimeFactory.Mock = null;
        }
    }
}